﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<link href="~/Content/styles/BillDetail.css?v=1.3" rel="stylesheet" />
<script src="~/Content/scripts/jquery/ajaxfileupload.js"></script>
<script>
    var keyValue = request('keyValue');
    var type = request('Type');
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    var BillState = 1, ApprovalState = 0;
    var hashTable = new Object();
    $(function () {
        initControl();
        GetGrid1();

    });
    function initControl() {
        var Mode = "@ViewBag.Mode";
        if (Mode == "True") {
            $("#Code").attr("placeholder", "系统已启用自动编号").attr("disabled", "disabled");
        } else {
            $("#Code").attr("isvalid", "yes").attr("checkexpession", "NotNull").attr("placeholder", "请输入编号");
        }

        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJson",
            description: "==请选择所属机构==",
            height: "250px",
            click: function (data) {
                _organizeid = data.id;
            }
        });
        $("#OrganizeId").ComboBoxTreeSetValue(_organizeid);

        if (!!keyValue) {
            $.SetForm({
                url: "../../PropertyManage/CS_Decorate/GetFormBillJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#BaseInfo").SetWebControls(data.data);
                    BillState = data.data.State;
                    $("#ApprovalInfo").SetWebControls(data.data2);
                    $('#SchemeInfo').ComboBoxTreeSetValue(data.data2.ApprovalSchemeInfoId);
                    ApprovalState = data.data2.ApprovalState;
                    $("#PStructId").val(data.PStructName).attr("title", data.data.PStructId);
                    $("#BeginDate").val(data.data2.DecorateBeginDate);
                    $("#EndDate").val(data.data2.DecorateEndDate);
                    $("#ApprovalState").val(data.data2.ApprovalState == 2 ? "已审批" : data.data2.ApprovalState == 1 ? "审批中" : "未审批");
                    GetGridAudit();
                    debugger;
                    if (data.data.State > 1) {
                        $("#BaseInfo input").attr('disabled', 'disabled');
                        $("#BaseInfo div").attr('disabled', 'disabled');
                        $("#BaseInfo textarea").attr('disabled', 'disabled');
                        $("#BaseInfo a").attr('disabled', 'disabled');
                        $("#btn_save").css("display", "none");
                        $("#btn_submit").css("display", "none");
                        GetGrid2();
                        $('.Approval').addClass('active');
                        $('.Base').removeClass('active');
                        $('.Polling').removeClass('active');
                        $('.Inspect').removeClass('active');
                        $('#line').addClass('two');
                        $('#line').removeClass('one');
                        $('#line').removeClass('three');
                        $('#line').removeClass('four');
                        $('#second').addClass('active');
                        $('#first').removeClass('active');
                        $('#third').removeClass('active');
                        $('#fourth').removeClass('active');
                    }
                    if (data.data.State > 2) {
                        if (data.data.IsHiddenChecked < 1) $("#btn_HiddenCheck").removeAttr('disabled');
                        if (data.data.State == 3 && data.data.IsHiddenChecked == 2) $("#btn_Decaoratefinish").removeAttr('disabled');
                        if (data.data.State == 4 && data.data.IsWholeChecked < 1) $("#btn_WholeCheck").removeAttr('disabled');
                        if (data.data.State == 5 && data.data.IsSecondChecked < 1) $("#btn_SecondCheck").removeAttr('disabled');
                    }
                }
            });
        }
    }
    //材料
    function GetGrid1() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridtable1');
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_MaterialSetting/GetFileList",
            postData: { "keyValue": keyValue },
            datatype: "json",
            height: 360,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Code", hidden: true },
                { label: "资料编号", name: "RuleCode", hidden: true },
                { label: "资料名称", name: "Name", index: "Name", width: 80, align: "left" },
                {
                    label: "必须提交", name: "IsSubmit", index: "IsSubmit", width: 80, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1)
                            return "<span style='color: #b91a1a;'>是</span>";
                        else
                            return "<span style='color: #cecece;'>否</span>";
                    }
                },
                 {
                     label: "必须上传", name: "IsUpload", index: "IsUpload", width: 80, align: "left",
                     formatter: function (cellvalue, options, rowObject) {
                         if (cellvalue == 1)
                             return "<span style='color: #b91a1a;'>是</span>";
                         else
                             return "<span style='color: #5cb85c;'>否</span>";
                     }
                 },
                  {
                      label: "是否提交", name: "CommitState", index: "CommitState", width: 80, align: "left",
                      formatter: function (cellvalue, options, rowObject) {
                          if (cellvalue == 1) return "<i class='fa fa-check-square-o ' style='margin-left:10px;'><i/>";
                          else return "<i class='fa fa-square-o' style='margin-left:10px;'><i/>";

                      }
                  },
                {
                    label: "是否上传", name: "UploadState", index: "UploadState", width: 80, align: "left",
                    formatter: function (cellvalue, options, rowObject) {;
                        if (cellvalue == 1)
                            return "<i class='fa fa-check ' style='margin-left:10px;'><i/>";
                        else {
                            if (BillState > 1) return "";
                            else
                                return " <i class='fa fa-upload' style='margin-left:10px;'><input class=\"fileImage\" id=\"fileImage_" + options.rowId + "_" + options.pos + "\"type=\"file\"  name=\"fileselect[]\"  style=\"position: absolute; width: 80px; height: 28px;opacity: 0; margin-top: -20px;  margin-left: -10px;\" onchange=\"UploadFile(" + options.rowId + "," + options.pos + ")\" /> ";
                        }

                    }
                },
                { label: "文件名", name: "FileName", index: "FileName", width: 100, align: "left", },
                 { label: "资料路径", name: "FileUrl", hidden: true },
                { label: "提交人", name: "CreateUserName", index: "CreateUserName", width: 80, align: "left" },
                { label: "提交人ID", name: "CreateUserId", hidden: true },
                { label: "提交时间", name: "CreateDate", index: "CreateDate", width: 80, align: "left" },
                { label: "接收人", name: "ReceiveUserName", index: "ReceiveUserName", width: 80, align: "center" },
                { label: "接收时间", name: "ReceiveDate", index: "ReceiveDate", width: 80, align: "left" },
                {
                    label: "是否合格", name: "IsQualified", index: "IsQualified", width: 100, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 1: return "<i class='fa fa-check fa-2x' style='color:green;margin-left:10px;'><i/>"; break;
                            default: return ""; break;
                        }
                    }
                },
                { label: "说明", name: "Memo", index: "Memo", width: 80, align: "left" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            hidegrid: false,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            onCellSelect: function (rowid, iCol, cellcontent, e) {
                if (iCol == 6 && BillState == 1) {
                    //提交资料
                    if (e.target.className == 'fa fa-square-o') {
                        $gridTable.setCell(rowid, iCol, "1");
                        $gridTable.setCell(rowid, 10, "@LeSoft.Application.Code.OperatorProvider.Provider.Current().UserName");
                        $gridTable.setCell(rowid, 11, "@LeSoft.Application.Code.OperatorProvider.Provider.Current().UserId");
                        $gridTable.setCell(rowid, 12, "@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")");
                    }
                    else {
                        $gridTable.setCell(rowid, iCol, "0");
                        $gridTable.setCell(rowid, 10, null);
                        $gridTable.setCell(rowid, 11, null);
                        $gridTable.setCell(rowid, 12, null);
                    }
                }
            }
        });
    }
    function UploadFile(rowid, iCol) {

        var rowData = $("#gridtable1").jqGrid('getRowData', rowid);
        var files = document.getElementById('fileImage_' + rowid + '_' + iCol).files;
        if (files.length > 0 && rowData != null) {
            $.ajaxFileUpload({
                url: "../../PropertyManage/CS_MaterialSetting/UploadFile",
                secureuri: false,
                fileElementId: 'fileImage_' + rowid + '_' + iCol,
                //dataType: 'json',
                data: { keyValue: rowData.RuleCode },
                success: function (data, status) {
                    window.name = "Form";
                    var resObj = JSON.parse(data.body.innerText);
                    var ss = resObj.resultdata.split(',');
                    hashTable[ss[0]] = ss[1];
                    $('#gridtable1').setCell(rowid, 8, files[0].name);
                    $('#gridtable1').setCell(rowid, 9, ss[1]);
                },
                error: function (data, status, e) {
                    alert(e);
                }
            });

        }

    }

    //验收记录
    function GetGrid2() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridtable2');
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_Inspection/GetBillList?BillCode=" + keyValue,
            datatype: "json",
            autowidth: true,
            height: 350,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "验收种类ID", name: "InspectType", index: "InspectType", hidden: true },
                { label: "验收种类", name: "InspectTypeName", index: "InspectTypeName", width: 100, align: "center" },
                { label: "验收单号", name: "Code", index: "BillCode", width: 100, align: "center" },
                { label: "创建人", name: "CreateUserName", index: "CreateUserName", width: 100, align: "center" },
                { label: "创建日期", name: "CreateDate", index: "CreateDate", width: 80, align: "center" },
                {
                    label: "验收状态", name: "State", width: 90, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "未验收"; break;
                            case 1: return "验收中"; break;
                            case 2: return "已验收"; break;
                            case 3: return "已取消"; break;
                            default: return ""; break;
                        }
                    }
                },
                {
                    label: "是否通过", name: "IsQualified", width: 90, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 1 ? "<i value=" + cellvalue + " class=\"fa fa-toggle-on\"></i>" : "<i value=" + cellvalue + " class=\"fa fa-toggle-off\" ></i>";
                    }
                },
                {
                    label: "是否审核", name: "AuditMark", width: 90, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "未审核"; break;
                            case 1: return "已审核"; break;
                            default: return ""; break;
                        }
                    }
                },
                { label: "审核人", name: "AuditUserName", index: "AuditUserName", width: 100, align: "center" },
                { label: "审核日期", name: "AuditDate", index: "AuditDate", width: 80, align: "center" },
                { label: "说明", name: "Memo", index: "Memo", width: 100, align: "center" }
            ],
            pager: false,
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            subGrid: true,
            subGridRowExpanded: function (subgrid_id, row_id) {
                var Type = $("#gridtable2").jqGrid('getRowData', row_id)['InspectType'];
                var BillCode = $("#gridtable2").jqGrid('getRowData', row_id)['Id'];
                var State = $("#gridtable2").jqGrid('getRowData', row_id)['State'];
                var subgrid_table_id = subgrid_id + "_t";
                var subhtml = "";
                subhtml += '<div><table id="' + subgrid_table_id + '"></table></table></div>';
                $("#" + subgrid_id).html(subhtml);
                $("#" + subgrid_table_id).jqGrid({
                    url: "../../PropertyManage/CS_Inspection/GetBillDetailList",
                    postData: {
                        Type: Type,
                        BillCode: BillCode
                    },
                    caption: "验收项目",
                    datatype: "json",
                    width: 1090,
                    height: 170,
                    colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "名称", name: "InspectionItemName", index: "InspectionItemName", width: 80, align: "center" },
                { label: "标准", name: "Criterion", index: "Criterion", width: 80, align: "center" },
                {
                    label: "责任部门", name: "ResponDepts", index: "ResponDepts", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return top.clientdepartmentData[cellvalue] == null ? "" : top.clientdepartmentData[cellvalue].FullName;
                    }
                },
                {
                    label: "是否通过", name: "IsPass", width: 90, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 1 ? "<i value=" + cellvalue + " class=\"fa fa-toggle-on\" style=\"cursor:pointer;\"></i>" : "<i value=" + cellvalue + " class=\"fa fa-toggle-off\" style=\"cursor:pointer;\"></i>";
                    }
                },
                { label: "说明", name: "Memo", index: "Memo", width: 80, align: "center", editable: true, edittype: "text" },
                { label: "验收人", name: "InspectionManName", index: "InspectionManName", width: 80, align: "center" },
                { label: "验收时间", name: "InspectionDate", index: "InspectionDate", width: 100, align: "center" }
                    ],
                    pager: false,
                    rowNum: "1000",
                    rownumbers: true,
                    hidegrid: false,
                    shrinkToFit: false,
                    gridview: true,
                    gridComplete: function () {
                        $("#" + this.id).setSelection(selectedRowIndex, false);
                        $('#' + this.id).closest("div.ui-jqgrid-view")
                        .children("div.ui-jqgrid-titlebar")
                        .css("text-align", "center")
                        .children("span.ui-jqgrid-title")
                        .css("float", "none");
                    },
                    ondblClickRow: function (rowid) {
                        EditSelectRow(rowid);
                        //selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                    },
                    onCellSelect: function (rowid, iCol, cellcontent) {
                        if (iCol != 5 || State == "已验收") { return false; }
                        var IsPass = 0;
                        if (cellcontent.indexOf("fa-toggle-on") > 0) {
                            IsPass = 0;
                        }
                        else { IsPass = 1; }
                        var rowdata = $("#" + subgrid_table_id).getRowData(rowid);
                        $.ajax({
                            url: "/PropertyManage/CS_Inspection/InspectionBillDetaiForm",
                            type: "POST",
                            async: false,
                            data: { "keyValue": rowdata.Id, "BillCode": BillCode, "Type": Type, "IsPass": IsPass },
                            success: function () {
                                $gridTable.trigger("reloadGrid");
                                $.currentIframe().$("#gridTable").trigger("reloadGrid");
                            }
                        });
                    }
                });

                //选中行启用行编辑
                function EditSelectRow(id) {
                    if (State == "已验收") { return false; }
                    if (selectedRowIndex != null && selectedRowIndex != "" && selectedRowIndex > 0) {
                        var rowdata = $("#" + subgrid_table_id).getRowData(selectedRowIndex);
                        var IsPass = 0;
                        if (rowdata.IsPass.indexOf("fa-toggle-on") > 0) {
                            IsPass = 1;
                        }
                        else { IsPass = 0; }
                        saveparameters = {
                            "successfunc": function () {
                                $gridTable.trigger("reloadGrid");
                                $.currentIframe().$("#gridTable").trigger("reloadGrid");
                            },
                            "url": '/PropertyManage/CS_Inspection/InspectionBillDetaiForm',
                            "extraparam": { "keyValue": rowdata.Id, "BillCode": BillCode, "Type": Type, "IsPass": IsPass },
                            "aftersavefunc": null,
                            "errorfunc": null,
                            "afterrestorefunc": null,
                            "restoreAfterError": true,
                            "mtype": "POST"
                        }
                        $("#" + subgrid_table_id).jqGrid('saveRow', selectedRowIndex, saveparameters);//保存上一行
                    }

                    var obj = $("#" + subgrid_table_id).getRowData(id);
                    var IsPass = 0;
                    if (obj.IsPass.indexOf("fa-toggle-on") > 0) {
                        IsPass = 1;
                    }
                    else { IsPass = 0; }
                    editparameters = {
                        "keys": true,
                        "oneditfunc": null,
                        "successfunc": function () {
                            $gridTable.trigger("reloadGrid");
                            $.currentIframe().$("#gridTable").trigger("reloadGrid");
                        },
                        "url": '/PropertyManage/CS_Inspection/InspectionBillDetaiForm',
                        "extraparam": { "keyValue": obj.Id, "BillCode": BillCode, "Type": Type, "IsPass": IsPass },
                        "aftersavefunc": null,
                        "errorfunc": null,
                        "afterrestorefunc": null,
                        "restoreAfterError": true,
                        "mtype": "POST"
                    }
                    //当前选中行
                    selectedRowIndex = id;//临时存储当前选中行
                    $("#" + subgrid_table_id).jqGrid('editRow', id, editparameters);
                }
            }
        });

    }

    //巡检
    function GetGrid3() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridtable3');
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_PollingResult/GetPollingItemInfo",
            postData: { "queryJson": JSON.stringify({ "Type": type, "ObjectId": keyValue }) },
            caption: "巡检记录",
            datatype: "json",
            width: 967,
            height: 660,
            hidegrid: false,
            colModel: [
               { label: "主键", name: "Id", index: "Id", hidden: true },
               { label: "编号", name: "Code", index: "Code", width: 150, align: "left" },
               { label: "名称", name: "Name", index: "Name", width: 300, align: "left" },
               {
                   label: "频次", name: "Frenquency", index: "Frenquency", width: 100, align: "left",
                   formatter: function (cellvalue, options, rowObject) {
                       switch (rowObject["Unit"]) {
                           case "0": return rowObject["UnitNum"] + "天" + cellvalue + "次";
                           case "1": return rowObject["UnitNum"] + "周" + cellvalue + "次";
                           case "2": return rowObject["UnitNum"] + "月" + cellvalue + "次";
                           case "3": return rowObject["UnitNum"] + "季" + cellvalue + "次";
                           case "4": return rowObject["UnitNum"] + "年" + cellvalue + "次";
                       }
                   }
               },
               { label: "已巡次数", name: "Count", index: "Count", width: 100, align: "left" },
               { label: "说明", name: "Memo", index: "Memo", width: 185, align: "left" }
            ],
            pager: false,
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (rowid) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                var obj = $("#" + this.id).getRowData(rowid);
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
                $("#" + this.id).setSelection(1);
            },
            subGrid: true,
            subGridRowExpanded: function (subgrid_id, row_id) {
                var itemId = $("#gridtable3").jqGrid('getRowData', row_id)['Id'];
                var subgrid_table_id = subgrid_id + "_t";
                var subhtml = "";
                subhtml += '<div><table id="' + subgrid_table_id + '"></table></table></div>';
                $("#" + subgrid_id).html(subhtml);
                $("#" + subgrid_table_id).jqGrid({
                    url: "../../PropertyManage/CS_PollingResult/GetPollingContentInfo",
                    postData: {
                        ObjectId: keyValue,
                        itemId: itemId
                    },
                    caption: "巡检内容",
                    datatype: "json",
                    width: 1090,
                    height: 170,
                    colModel: [
                        { label: "主键", name: "id", index: "id", hidden: true },
                         { label: "巡检时间", name: "createdate", index: "createdate", width: 100, align: "center" },
                         { label: "巡检人", name: "createusername", index: "createusername", width: 100, align: "center" },
                           {
                               label: "类型", name: "category", index: "category", width: 100, align: "center",
                               formatter: function (cellvalue, options, rowObject) {
                                   return cellvalue == 0 ? "录入型" : "选择型";
                               }
                           },
                         {
                             label: "具体内容", name: "typedescription", width: 400, align: "left", sortable: false,
                             formatter: function (cellvalue, options, rowObject) {

                                 var obj = JSON.parse(cellvalue);
                                 if (rowObject.Type == 0) {
                                     var ss = "1、" + rowObject.Name;
                                     //录入型
                                     if (obj[0].ValueType == "数值型") {
                                         var s = obj[0].IsException == 1 ? "范围外属于异常值" : "范围内属于异常值";
                                         ss += "<sapn style='color:red;'>（最小值:" + obj[0].MinValue + " 最大值:" + obj[0].MaxValue + "在这个" + s + "）</span>\n";
                                     }
                                     if (rowObject.CheckWay != "") {
                                         ss += " <sapn style='color: black;'>检查方法:" + rowObject.CheckWay + "</span>";
                                     }
                                     if (rowObject.Criterion != "") {
                                         ss += "  <sapn style='color: black;'>标准:" + rowObject.Criterion + "</span>";
                                     }
                                     ss += "\n<span style='color: black;'>    " + rowObject.Text + "</span>";
                                     return ss;
                                 }
                                 else {
                                     var ss = "1、" + rowObject.Name + "\n";
                                     if (rowObject.CheckWay != "") {
                                         ss += " <sapn>检查方法:" + rowObject.CheckWay + "</span>";
                                     }
                                     if (rowObject.Criterion != "") {
                                         ss += "  <sapn>标准:" + rowObject.Criterion + "</span>";
                                     }
                                     ss += "\n";
                                     for (var i = 0; i < obj.length; i++) {
                                         if (obj[i].Value == rowObject.Value) ss += '<span style="color: black;"> <label><input disabled name="IsSendMessage" type="radio" checked="checked" value="' + obj[i].Value + '" />' + obj[i].Flag + ' ' + obj[i].Text + '</label></span>';
                                         else {
                                             ss += '<span style="color: black;"> <label><input disabled name="IsSendMessage" type="radio" value="' + obj[i].Value + '" />' + obj[i].Flag + ' ' + obj[i].Text + '</label></span>';
                                         }
                                     }
                                     return ss;
                                 }

                             }
                         },
                        {
                            label: "是否异常", name: "isexception", width: 80, align: "left", sortable: false,
                            formatter: function (cellvalue, options, rowObject) {
                                return cellvalue == 0 ? "<span value=" + cellvalue + " class='label label-success'>正常</span>" : "<span class='label label-danger' value=" + cellvalue + ">异常</span>";
                            }
                        },
                        { label: "备注", name: "memo", index: "memo", width: 100, align: "center" }
                    ],
                    pager: false,
                    rowNum: "1000",
                    rownumbers: true,
                    hidegrid: false,
                    shrinkToFit: false,
                    gridview: true,
                    onSelectRow: function () {
                        selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                    },
                    gridComplete: function () {
                        // $("#" + this.id).setSelection(selectedRowIndex, false);
                        $('#' + this.id).closest("div.ui-jqgrid-view")
                        .children("div.ui-jqgrid-titlebar")
                        .css("text-align", "center")
                        .children("span.ui-jqgrid-title")
                        .css("float", "none");
                    }


                });
            }
        });
        $gridTable.closest("div.ui-jqgrid-view")
              .children("div.ui-jqgrid-titlebar")
              .css("text-align", "center")
              .children("span.ui-jqgrid-title")
              .css("float", "none");

    }

    //整改
    function GetGrid4() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridtable4');
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_Decorate/GetAbarbeitungList",
            postData: { SourceId: keyValue },
            datatype: "json",
            caption: "整改记录",
            width: 967,
            height: 700,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "单据日期", name: "Date", index: "Date", width: 80, align: "center" },
                { label: "单据编号", name: "Code", index: "Code", width: 100, align: "center" },
                { label: "整改内容", name: "ContentDetail", index: "ContentDetail", width: 150, align: "center" },
                { label: "整改期限", name: "DateLimit", index: "DateLimit", width: 80, align: "center" },
                { label: "创建人", name: "CreateUserName", index: "CreateUserName", width: 90, align: "center" },
                {
                    label: "单据状态", name: "State", width: 70, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "<span class='fa' style='color:red;margin-left:10px;'>未完成</span>"; break;
                            case 1: return "<span class='fa' style='color:green;margin-left:10px;'>已完成</span>"; break;
                            case 2: return "<span class='fa' style='color:red;margin-left:10px;'>重做中</span>"; break
                            case 3: return "<span class='fa' style='color:green;margin-left:10px;'>已取消</span>"; break;
                        }
                    }
                },
                { label: "状态说明", name: "StateMemo", index: "StateMemo", width: 100, align: "center" },
                {
                    label: "是否需要复验", name: "CheckMark", width: 90, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 0) return "否";
                        else return "是";
                    }
                },
                { label: "复验人", name: "CheckUserName", index: "CheckUserName", width: 90, align: "center" },
                 {
                     label: "复验状态", name: "CheckFlag", width: 70, align: "center", sortable: false,
                     formatter: function (cellvalue, options, rowObject) {
                         switch (cellvalue) {
                             case 0: return "<span class='fa' style='color:red;'>未通过</span>"; break;
                             case 1: return "<span class='fa' style='color:green;'>通过</span>"; break;
                             default: return "<span class='fa' style='color:red;'>待复验</span>"; break;
                         }
                     }
                 },
                { label: "复验说明", name: "CheckMemo", index: "CheckMemo", width: 130, align: "center" }
            ],
            pager: false,
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        $gridTable.closest("div.ui-jqgrid-view")
           .children("div.ui-jqgrid-titlebar")
           .css("text-align", "center")
           .children("span.ui-jqgrid-title")
           .css("float", "none");
    }



    function AcceptClick(Type) {
        if (Type == 2 && (BillState < 2 && !$('#BaseInfo').Validform())) {
            return false;
        }
        //基础信息
        var BaseInfo = $("#BaseInfo").GetWebControls(keyValue);
        BaseInfo["State"] = BillState;
        BaseInfo["PStructId"] = $("#PStructId").attr("title");
        BaseInfo["CustomerId"] = $("#CustomerName").attr("title");
        //材料
        var obj = $("#gridtable1").jqGrid("getRowData");
        var scount = 0, ucount = 0;
        for (var i = 0; i < obj.length; i++) {
            obj[i].IsSubmit = obj[i].IsSubmit.indexOf("是") > 0 ? 1 : 0;
            obj[i].IsUpload = obj[i].IsUpload.indexOf("是") > 0 ? 1 : 0;
            obj[i].CommitState = obj[i].CommitState.indexOf("check") > 0 ? 1 : 0;
            obj[i].UploadState = obj[i].FileUrl != null ? 1 : 0;
            if (obj[i].IsSubmit == 1 && obj[i].CreateDate == "") scount++;
            if (obj[i].IsUpload == 1 && obj[i].FileUrl == "") ucount++;
        }
        var params = { "keyValue": keyValue, "Type": Type, "BaseInfo": JSON.stringify(BaseInfo), "fileInfo": JSON.stringify(obj) };
        if (BillState < 2 && Type == 2 && (ucount > 0 || scount > 0)) {
            dialogMsg('有文件没有上传或提交！', 0);
        }
        else {
            $.SaveForm({
                url: "../../PropertyManage/CS_Decorate/SaveForm",
                param: params,
                loading: "正在保存数据...",
                success: function () {
                    $.currentIframe().$("#gridTable").trigger("reloadGrid");
                    //dialogClose();
                }
            });
        }


    }

    //新增验收单
    function btn_Inspectionadd(type) {
        dialogOpen({
            id: "Form1",
            title: '添加验收单',
            url: '/PropertyManage/CS_Inspection/InspectionBillForm?BillCode=' + keyValue + "&Type=" + type,
            width: "750px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }

    //词典
    function DataItemSelect(type) {
        if ($("#OrganizeId").attr('data-value') == undefined) {
            dialogMsg("请先选择机构", 0);
        } else {
            var options = {};
            switch (type) {
                case 1: {
                    var data = [{ id: "PStructId", text: "", value: "" }, { id: "CustomerName", text: "", value: "" }, { id: "Cname", text: "", value: "" }, { id: "Ccode", text: "", value: "" }, { id: "Area", text: "", value: "" }, { id: "CLname", text: "", value: "" }, { id: "CLphone", text: "", value: "" }];
                    options = {
                        category: 4,
                        type: 1,
                        organizeid: $("#OrganizeId").attr('data-value'),
                        data: data
                    };
                }; break;
            }
            DataItemClick(JSON.stringify(options));
        }
    }

    //加载审核记录
    function GetGridAudit() {
        var $gridTable = $("#gridTable5");
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_Decorate/GetAuditList?BillId=" + keyValue,
            datatype: "json",
            height: 110,
            autowidth: true,
            unwritten: false,
            colModel: [
                    { label: 'ID', name: 'Id', hidden: true },
                    {
                        label: "审批结果", name: "AuditState", width: 200, align: "left", sortable: true,
                        formatter: function (cellvalue, options, rowObject) {
                            switch (cellvalue) {
                                case 2: return "不通过";
                                case 1: return "通过";
                                default: return "";
                            }
                        }
                    },
                    {
                        label: '审批人', name: 'AuditMan', width: 200, align: "left", sortable: false,
                        formatter: function (cellvalue, options, rowObject) {
                            return top.clientuserData[cellvalue] == null ? cellvalue : top.clientuserData[cellvalue].RealName;
                        }
                    },
                    { label: "审批时间", name: "AuditTime", width: 200, align: "left", sortable: false },
                    { label: "审批意见", name: "AuditMemo", width: 310, align: "left", sortable: false }
            ],
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            hidegrid: false,
            gridComplete: function () {
                if ($("#ApprovalState").val() != "已审批")
                    GetIsShow();
            }
        });
    }

    function btn_Audit(AuditState) {
        var queryJson = $("#AuditState").GetWebControls(keyValue);
        queryJson["AuditState"] = AuditState;
        queryJson["Level"] = $("#gridTable5").jqGrid("getRowData").length + 1;
        queryJson["BillId"] = keyValue;
        queryJson["AuditType"] = 0;
        $.SaveForm({
            url: "../../PropertyManage/CS_Decorate/SaveAuditForm",
            param: queryJson,
            loading: "正在保存数据...",
            success: function () {
                $("#gridTable5").resetSelection();
                $("#gridTable5").trigger("reloadGrid");
                if ($("#ApprovalState").val() != "已审批")
                    GetIsShow();
            }
        })
    }

    function GetIsShow() {
        $.SetForm({
            url: "../../SystemManage/Setting/GetIsShow",
            param: { TypeName: "装修单", Level: $("#gridTable5").jqGrid('getDataIDs').length },
            dataType: "text",
            success: function (data) {
                var Audit = JSON.parse(data);
                var Html = "";
                if (Audit.OK) {
                    $("#AuditState").show();
                    NowLevel = Audit.NowLevel;
                    if (Audit.HasHandling == 1) {
                        var HandleConditionJson = JSON.parse(Audit.HandleConditionJson);
                        for (var i = 0; i < HandleConditionJson.length; i++) {
                            if (HandleConditionJson[i].Type == "1") {
                                Html += "<td class=\"formTitle\"><input id=\"" + HandleConditionJson[i].FieldId + "\" type=\"checkbox\" class=\"WorkAudit\" title=\"" + HandleConditionJson[i].FieldName + "\" /></td>";
                                Html += "<td class=\"formValue\" >" + HandleConditionJson[i].FieldName + "</td>";
                            }
                            if (HandleConditionJson[i].Type == "2") {
                                Html += "<td class=\"formTitle\">" + HandleConditionJson[i].FieldName + "<font face=\"宋体\">*</font></td>";
                                Html += "<td class=\"formValue\"><input id=\"" + HandleConditionJson[i].FieldId + "\" type=\"text\" class=\"form-control WorkAudit\" isvalid=\"yes\" checkexpession=\"NotNull\" title=\"" + HandleConditionJson[i].FieldName + "\" /></td>";
                            }
                        }
                        $("#WorkAudit").html(Html);
                        if (ShowType == 1) {
                            $("#WorkAudit").html("");
                        }
                    }
                }
                else
                    $("#AuditState").hide();
            }
        });
    }

    function Decoratefinishbtn() {
        $.SaveForm({
            url: "../../PropertyManage/CS_Decorate/Decoratefinish?keyValue=" + keyValue,
            loading: "正在保存数据...",
            success: function () {
                reload();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }
</script>

<div id="wrapper" style="background:#fff;">
    <div id="left-side">
        <ul>
            <li class="Base active">
                制单提交
            </li>
            <li class="Approval">
                审批验收
            </li>
            <li class="Polling">
                巡检记录
            </li>
            <li class="Inspect">
                整改记录
            </li>
        </ul>
    </div>
    <div id="border">
        <div id="line" class="one"></div>
    </div>
    <div id="right-side" class="tab-content">
        <div id="first" class="tab-pane active" style=" height: 100%; overflow-y: scroll;">
            <table id="BaseInfo" class="form">
                <tr>
                    <td class="formTitle">所属机构<font face="宋体">*</font></td>
                    <td class="formValue">
                        <div id="OrganizeId" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
                    </td>
                    <td class="formTitle">单据编号<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="Code" type="text" class="form-control" placeholder="系统自动编号" />
                    </td>
                    <td class="formTitle">单据日期<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="Date" type="text" class="form-control input-wdatepicker" value="@LeSoft.Util.Time.GetToday("yyyy-MM-dd HH:mm:ss")" placeholder="请输入单据日期" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle" id="PSFullNameTD">商铺名称<font face="宋体">*</font></td>
                    <td class="formValue" colspan="3">
                        <div class="input-group" style="width: 100%;">
                            <input id="PStructId" type="text" class="form-control BaseClass" isvalid="yes" checkexpession="NotNull">
                            <span class="input-group-btn BaseClass">
                                <a onclick="DataItemSelect(1)" class="form-control BaseClass" style="cursor: pointer"><i class="fa fa fa-book " style=" font-size: 20px; padding-right: 5px; padding-top: 3px; color: gray"></i></a>
                            </span>
                        </div>
                    </td>
                    <td class="formTitle">业户名称<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="CustomerName" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">申请人<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="Cname" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                    </td>
                    <td class="formTitle">申请人编号</td>
                    <td class="formValue">
                        <input id="Ccode" type="text" class="form-control" />
                    </td>
                    <td class="formTitle">装修面积<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="Area" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">联系人<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="CLname" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                    </td>
                    <td class="formTitle">联系人电话<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="CLphone" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                    </td>
                    <td class="formTitle">经营品牌</td>
                    <td class="formValue">
                        <input id="Brand" type="text" class="form-control" />
                    </td>
                </tr>
                <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td> </tr>
                <tr>
                    <td class="formTitle">施工单位<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="ConstructionUnit" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                    </td>
                    <td class="formTitle">施工负责人<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="ConstructionManager" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                    </td>
                    <td class="formTitle">联系电话<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="CMLphone" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">计划开始日期<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="PBeginDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'PEndDate\')}'})" isvalid="yes" checkexpession="NotNull" />
                    </td>
                    <td class="formTitle">计划结束日期<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="PEndDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({ minDate: '#F{$dp.$D(\'PBeginDate\')}' })" isvalid="yes" checkexpession="NotNull" />
                    </td>
                    <td class="formTitle">施工人数<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="CMLnum" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">电容量</td>
                    <td class="formValue">
                        <input id="Capacity" type="text" class="form-control" />
                    </td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 4px;line-height:50px;">
                        附加说明
                    </th>
                    <td class="formValue" colspan="5">
                        <textarea id="Memo" class="form-control" style="height: 50px;"></textarea>
                    </td>
                </tr>
                <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td> </tr>
                <tr>
                    <td colspan="6">
                        <div class="panel-Title">资料提交</div>
                        <table id="gridtable1"></table>
                    </td>
                </tr>
            </table>
            <style>
                .ui-jqgrid .ui-jqgrid-caption {
                    text-align: right;
                    padding-right: 5px;
                    background-color: #F5F5F5;
                }
            </style>
        </div>
        <div id="second" class="tab-pane" style="height: 100%; overflow-y: scroll;">
            <table id="ApprovalInfo" class="form">
                <tr>
                    <td class="formTitle">审批开始日期<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="ApprovalBeginDate" readonly type="text" class="form-control  input-wdatepicker approvalclass" @*onfocus="WdatePicker()"*@ />
                    </td>
                    <td class="formTitle">审批结束日期<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="ApprovalEndDate" readonly type="text" class="form-control  input-wdatepicker approvalclass" @*onfocus="WdatePicker()"*@ />
                    </td>
                    <td class="formTitle">审批状态</td>
                    <td class="formValue">
                        <input id="ApprovalState" readonly type="text" class="form-control" placeholder="未审批" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">最终审批人</td>
                    <td class="formValue">
                        <input id="ApprovalLastMan" readonly type="text" class="form-control approvalclass" />
                    </td>
                    <td class="formTitle">许可证编号</td>
                    <td class="formValue">
                        <input id="LicenseCode" readonly type="text" class="form-control approvalclass" />
                    </td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 4px;line-height:50px;">
                        最终审批意见
                    </th>
                    <td colspan="5">
                        <textarea id="ApprovalLastSugg" readonly="readonly" class="form-control approvalclass" style="height: 50px;"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="6">
                        <div class="gridPanel" style="width: 100%;padding-left:5px;">
                            <table id="gridTable5"></table>
                        </div>
                    </td>
                </tr>
                <tr id="AuditState" hidden>
                    <td class="formTitle">审批意见：</td>
                    <td class="formValue" colspan="3"><input id="AuditMemo" class="form-control" type="text" /></td>
                    <td class="formValue" colspan="2">
                        <a id="lr-addRule" class="btn btn-success btn-xs" style="width:150px;height:28px;" onclick="btn_Audit(1)"><i class="fa fa-plus"></i>&nbsp;同意</a>
                        <a id="lr-deleteRule" class="btn btn-danger btn-xs" style="width: 150px; height: 28px;" onclick="btn_Audit(2)"><i class="fa fa-trash-o"></i>&nbsp;不同意</a>
                    </td>
                </tr>
                <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td> </tr>
                <tr>
                    <td class="formTitle"></td>
                    <td colspan="5">
                        <a id="btn_HiddenCheck" disabled class="btn btn-success" onclick="btn_Inspectionadd(1);"><i class="fa fa-plus"></i>隐蔽工程验收</a>
                        <a id="btn_Decaoratefinish" disabled class="btn btn-success" onclick="Decoratefinishbtn();">结束装修</a>
                        <a id="btn_WholeCheck" disabled class="btn btn-success" onclick="btn_Inspectionadd(2);">整体工程验收</a>
                        <a id="btn_SecondCheck" disabled class="btn btn-success" onclick="btn_Inspectionadd(3);">二次验收</a>
                    </td>
                </tr>
                <tr style=" height: 3px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td> </tr>
                <tr hidden>
                    <td class="formTitle"> 装修结束时间：</td>
                    <td class="formValue">
                        <input id="DecorateEndDate" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" type="text" class="form-control input-wdatepicker" />
                    </td>
                    <td class="formTitle">装修结束说明：</td>
                    <td class="formValue" colspan="3">
                        <textarea id="EndMemo" class="form-control"></textarea>
                    </td>
                </tr>
                <tr style=" height: 3px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td> </tr>
                <tr>
                    <td colspan="6">
                        <div class="gridPanel" style="width: 100%;padding-left:5px;">
                            <table id="gridtable2"></table>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div id="third" class="tab-pane" style="height:100%; overflow-y: scroll;">
            <table class="form">
                <tr>
                    <td class="formTitle">巡检开始日期<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="BeginDate" type="text" class="form-control" readonly />
                    </td>
                    <td class="formTitle">巡检结束日期<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="EndDate" type="text" class="form-control" readonly />
                    </td>
                </tr>
                <tr style=" height: 10px; border-bottom: 1px dashed #cecece;"><td colspan="4"></td> </tr>
                <tr>
                    <td colspan="4">
                        <div class="gridPanel" style="width: 100%;padding-left:5px;">
                            <table id="gridtable3"></table>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div id="fourth" class="tab-pane active" style="height: 100%; overflow-y: scroll;">
            <div class="gridPanel" style="width: 100%;">
                <table id="gridtable4"></table>
            </div>
        </div>
    </div>
    <div class="form-button" id="wizard-actions">
        <a id="btn_save" class="btn  btn-success" onclick="AcceptClick(1);">保存</a>
        <a id="btn_submit" class="btn btn-info" onclick="AcceptClick(2);">提交</a>
    </div>
    <script>
        $('.Base').click(function () {
            $('.Base').addClass('active');
            $('.Approval').removeClass('active');
            $('.Polling').removeClass('active');
            $('.Inspect').removeClass('active');
            $('#line').addClass('one');
            $('#line').removeClass('two');
            $('#line').removeClass('three');
            $('#line').removeClass('four');
            $('#first').addClass('active');
            $('#second').removeClass('active');
            $('#third').removeClass('active');
            $('#fourth').removeClass('active');
        });
        $('.Approval').click(function () {
            GetGrid2();
            $('.Approval').addClass('active');
            $('.Base').removeClass('active');
            $('.Polling').removeClass('active');
            $('.Inspect').removeClass('active');
            $('#line').addClass('two');
            $('#line').removeClass('one');
            $('#line').removeClass('three');
            $('#line').removeClass('four');
            $('#second').addClass('active');
            $('#first').removeClass('active');
            $('#third').removeClass('active');
            $('#fourth').removeClass('active');

        });
        $('.Polling').click(function () {
            GetGrid3();
            $('.Polling').addClass('active');
            $('.Approval').removeClass('active');
            $('.Base').removeClass('active');
            $('.Inspect').removeClass('active');
            $('#line').addClass('three');
            $('#line').removeClass('one');
            $('#line').removeClass('two');
            $('#line').removeClass('four');
            $('#third').addClass('active');
            $('#first').removeClass('active');
            $('#second').removeClass('active');
            $('#fourth').removeClass('active');
        });
        $('.Inspect').click(function () {
            GetGrid4();
            $('.Inspect').addClass('active');
            $('.Approval').removeClass('active');
            $('.Base').removeClass('active');
            $('.Polling').removeClass('active');
            $('#line').addClass('four');
            $('#line').removeClass('one');
            $('#line').removeClass('two');
            $('#line').removeClass('three');
            $('#fourth').addClass('active');
            $('#first').removeClass('active');
            $('#second').removeClass('active');
            $('#third').removeClass('active');

        });
    </script>
</div>
